import Mock from 'mockjs'
import DynamicRouter from '@/test/dynamicRouter.json'

// 定义 user 登录
Mock.mock('/api/user/login', 'post', () => {
  return {
    code: 200,
    msg: '成功',
    data: {
      token: 'user',
    },
  }
})

// 定义 admin 登录
Mock.mock('/api/admin/login', 'post', () => {
  return {
    code: 200,
    msg: '成功',
    data: {
      token: 'admin',
    },
  }
})

// 退出登录
Mock.mock('/api/logout', 'post', () => {
  return {
    code: 200,
    msg: '成功',
    data: {},
  }
})

// 获取按钮权限
Mock.mock('/api/auth/buttons', 'post', () => {
  const token = JSON.parse(sessionStorage.getItem('GlobalState')).token
  const data = token === 'admin' ? ['add', 'edit', 'delete', 'import', 'export'] : ['add', 'edit']
  return {
    code: 200,
    msg: '成功',
    data: {
      authButton: data,
    },
  }
})


// 获取菜单权限
Mock.mock('/api/menu/list', 'post', () => {
  const token = JSON.parse(sessionStorage.getItem('GlobalState')).token
  const data = token === 'admin' ? DynamicRouter : DynamicRouter.filter((item)=> item.name === 'home' || item.name === 'auth')
  return {
    code: 200,
    msg: '成功',
    data
  }
})
